


# 使用与开发时版本匹配的基础镜像
FROM golang:1.20-alpine AS build

# 设置工作路径
WORKDIR /go/src/app

# 项目整体拷贝
COPY . .
#原始方式：直接镜像内打包编译
RUN export GO111MODULE=auto && export GOPROXY=https://goproxy.cn && go mod tidy

# 编译go源代码 并命名为go_gateway 存放到 /bin/go_gateway
RUN CGO_ENABLED=0 GOOS=linux go build -o ./bin/service


FROM alpine

# 注册到服务中心的ip
WORKDIR /

ENV SERVICE_IP "192.168.116.131"
# 运行端口
ENV SERVICE_PORT "9210"
# 运行模式

# 更换镜像源 配置时区
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk update && apk add tzdata

COPY --from=build /go/src/app/bin/service /service
COPY --from=build /go/src/app/config-debug.yaml /config-debug.yaml


# 暴露端口
EXPOSE $SERVICE_PORT
# 执行
# ENTRYPOINT ["/service -mode=$MODE -sip=$SERVICE_IP -port=$SERVICE_PORT"]
ENTRYPOINT [ "/service  -sip=${SERVICE_IP} -port=${SERVICE_IP}"]